import time

from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import redirect
from django.http import HttpResponse

class VerifycodeMiddleware(MiddlewareMixin):
    def process_request(self, request):
        print("***verifycode_middleware***", request.path)
        print(" request.path:", request.path)
        print("request.method :",request.method )
        print( request.path.find("/loginPage"))
        if request.path.find("/loginPage")>-1 and request.method == "POST":
            print("check verifycode")
            # 判断验证码
            verifycode = request.POST.get("verifyPicture")
            if  verifycode.upper() != request.session.get("verifycode_session").upper():
                return redirect("/loginPage")